package top.wardyan.wdev.dbdevassist.action.tf;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import top.wardyan.base.model.TableField;
import top.wardyan.base.util.DateUtil;
import top.wardyan.wdev.dbdevassist.action.base.BaseMasterDetailsEditShell;
import top.wardyan.wdev.dbdevassist.model.YTObjectCol;
import top.wardyan.wdev.dbdevassist.model.YTObjectPara;

@SuppressWarnings("unused")
public class TableFuncEditShell extends BaseMasterDetailsEditShell<TableFuncEditShell>{

	
	
//	public ProcEditShell() {
//		this(1, "gp_qryreceive_item");
//	}
	
	public TableFuncEditShell(int sID, String xName) {
		super(sID, xName, 3);
		this.createContent();
	}
	
	private void createContent() {
		
		
	}

	
	
	

	



	

	


	
	@Override
	protected void getParas() {
		List<Record> rs = Db.use().find("select p.name, p.parameter_id, p.system_type_id from sys.parameters AS p INNER JOIN sys.objects as b on b.object_id = p.object_id where b.name = ?",  xName);
		if(rs != null) {
			for(Record r : rs) {
				String name = r.getStr("name");
				YTObjectPara para = paraService.find(self.sID, name);
				if(para == null) {
					para = new YTObjectPara().setMID(self.sID).setRAuthorID(dda.user.getSID())
							.setRDicID(0).setSCreateTime(DateUtil.getCurrentTimestamp()).setSLastUpdate(DateUtil.getCurrentTimestamp())
							.setSStatus(2).setSVersion(1).setXDesc("").setXField(name).setXHint("").setXMainName(xName).setXName("")
							.setXNote("");
							//.setXTableName("").setXType(0);
					paraService.save(para);
				}
			}
		}
		this.refreshParas();
	}

	@Override
	protected void getCols() {
		List<Record> rs = Db.use().find("select p.name from sys.columns AS p INNER JOIN sys.objects as b on b.object_id = p.object_id where b.name = ?",  xName);
		if(rs != null) {
			for(Record r : rs) {
				YTObjectCol c = dda.objectColService.find(self.sID, r.getStr("name"));
				if(c == null) {
					c = new YTObjectCol().setMID(self.sID)
							.setRAuthorID(dda.user.getSID())
							.setRDicID(0).setSStatus(2)
							.setSVersion(1).setXDesc("").setXField(r.getStr("name")).setXHint("")
							.setXMainName(xName).setXName("").setXNote("")
							.setXType(0).setXTableName("")
							;
					dda.objectColService.save(c);
				}
			}
			
		}
		this.refreshCols();
	}

	@Override
	protected int getTypeID() {
		return 24;
	}
	
}
